/*
 * @Author: your name
 * @Date: 2021-05-09 18:44:40
 * @LastEditTime: 2021-05-12 11:36:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \after-end\app\controller\routes.js
 */
'use strict';

const Controller = require('egg').Controller;

class RoutesController extends Controller {

    //后台管理查找路由
    async fandRoutes() {
        const { ctx } = this;
        const data = await ctx.service.routes.fandRoutes();
        ctx.body = data;
    }



    async addList() {
        const { ctx, app } = this;
        const inster = async (item2) => {
            await app.mysql.insert("routesTable", { url: item2.url, path: item2.path, name: item2.name, icon: item2.icon, component: item2.component, key: item2.key });
        }
        const list = [
            //系统
            {
                path: "/system",
                name: "系统",
                icon: "smile",
                routes: [
                    //模块管理
                    {
                        path: "/system/moduleManageMent",
                        name: "模块管理",
                        icon: "smile",
                        routes: [
                            //地区管理
                            {
                                path: "/system/moduleManageMent/areaManageMent",
                                name: "地区管理",
                                icon: "smile",
                                component: "@/pages/System/ModuleManageMent/AreaManageMent",
                            },
                            //地区管理
                            {
                                path: "/system/moduleManageMent/schoolManageMent",
                                name: "学校管理",
                                icon: "smile",
                                component: "@/pages/System/ModuleManageMent/SchoolManageMent",
                            },
                            //地铁管理
                            {
                                path: "/system/moduleManageMent/subwayManagement",
                                name: "地铁管理",
                                icon: "smile",
                                component: "@/pages/System/ModuleManageMent/SubwayManagement",
                            },
                            //广告位管理
                            {
                                path: "/system/moduleManageMent/advertisingManagement",
                                name: "广告位管理",
                                icon: "smile",
                                component: "@/pages/System/ModuleManageMent/AdvertisingManagement",
                            },
                            //推荐位管理
                            {
                                path: "/system/moduleManageMent/recommendationManagement",
                                name: "推荐位管理",
                                icon: "smile",
                                component: "@/pages/System/ModuleManageMent/RecommendationManagement",
                            },
                        ],
                    },
                    //权限管理
                    {
                        path: "/system/authorityManageMent",
                        name: "权限管理",
                        icon: "smile",
                        routes: [
                            //人员管理
                            {
                                path: "/system/authorityManageMent/personManageMent",
                                name: "人员管理",
                                icon: "smile",
                                component: "@/pages/System/AuthorityManageMent/PersonManageMent",
                            },
                            //角色管理
                            {
                                path: "/system/authorityManageMent/roleManageMent",
                                name: "角色管理",
                                icon: "smile",
                                component: "@/pages/System/AuthorityManageMent/RoleManageMent",
                            },
                        ],
                    },
                ],
            },
            //楼盘
            {
                path: "/floor",
                name: "楼盘",
                icon: "smile",
                routes: [
                    //楼盘管理
                    {
                        path: "/floor/floorManageMent",
                        name: "楼盘管理",
                        icon: "smile",
                        routes: [
                            //楼盘列表
                            {
                                path: "/floor/floorManageMent/floorList",
                                name: "楼盘列表",
                                icon: "smile",
                                component: "@/pages/Floor/FloorManageMent/FloorList",
                            },
                        ],
                    },
                    //开发商管理
                    {
                        path: "/floor/developers",
                        name: "开发商管理",
                        icon: "smile",
                        routes: [
                            //开发商列表
                            {
                                path: "/floor/developers/developersList",
                                name: "开发商列表",
                                icon: "smile",
                                component: "@/pages/Floor/Developers/DevelopersList",
                            },
                        ],
                    },
                    //团购管理
                    {
                        path: "/floor/groupBuying",
                        name: "团购管理",
                        icon: "smile",
                        routes: [
                            //团购列表
                            {
                                path: "/floor/groupBuying/groupList",
                                name: "团购列表",
                                icon: "smile",
                                component: "@/pages/Floor/GroupBuying/GroupList",
                            },
                        ],
                    },
                ],
            },
            //二手出租
            {
                path: "/secondHand",
                name: "二手/出租",
                icon: "smile",
                routes: [
                    //小区管理
                    {
                        path: "/secondHand/estateManageMent",
                        name: "小区管理",
                        icon: "smile",
                        routes: [
                            //小区列表
                            {
                                path: "/secondHand/estateManageMent/estateList",
                                name: "小区列表",
                                icon: "smile",
                                component: "@/pages/SecondHand/EstateManageMent/EstateList",
                            },
                            //成交列表
                            {
                                path: "/secondHand/estateManageMent/transactionList",
                                name: "成交列表",
                                icon: "smile",
                                component: "@/pages/SecondHand/EstateManageMent/TransactionList",
                            },
                        ],
                    },
                    //二手房
                    {
                        path: "/secondHand/resoldApartment",
                        name: "二手房",
                        icon: "smile",
                        routes: [
                            //房源管理
                            {
                                path: "/secondHand/resoldApartment/houseResource",
                                name: "房源管理",
                                icon: "smile",
                                component: "@/pages/SecondHand/ResoldApartment/HouseResource",
                            },
                        ],
                    },
                    //出租房
                    {
                        path: "/secondHand/rentOut",
                        name: "出租房",
                        icon: "smile",
                        routes: [
                            //房源管理
                            {
                                path: "/secondHand/rentOut/houseResource",
                                name: "房源管理",
                                icon: "smile",
                                component: "@/pages/SecondHand/RentOut/HouseResource",
                            },
                        ],
                    },
                ],
            },
            //商业
            {
                path: "/business",
                name: "商业",
                icon: "smile",
                routes: [
                    //写字楼
                    {
                        path: "/business/officeBuilding",
                        name: "写字楼",
                        icon: "smile",
                        routes: [
                            //出售管理
                            {
                                path: "/business/officeBuilding/saleManageMent",
                                name: "出售管理",
                                icon: "smile",
                                component: "@/pages/Business/OfficeBuilding/SaleManageMent",
                            },
                            //出租管理
                            {
                                path: "/business/officeBuilding/rendOutManageMent",
                                name: "出租管理",
                                icon: "smile",
                                component: "@/pages/Business/OfficeBuilding/RendOutManageMent",
                            },
                        ],
                    },
                    //商铺
                    {
                        path: "/business/shoppimgMall",
                        name: "商铺",
                        icon: "smile",
                        routes: [
                            //出售管理
                            {
                                path: "/business/shoppimgMall/saleManageMent",
                                name: "出售管理",
                                icon: "smile",
                                component: "@/pages/Business/ShoppimgMall/SaleManageMent",
                            },
                            //出租管理
                            {
                                path: "/business/shoppimgMall/rendOutManageMent",
                                name: "出租管理",
                                icon: "smile",
                                component: "@/pages/Business/ShoppimgMall/RendOutManageMent",
                            },
                        ],
                    },
                ],
            },
            //内容
            {
                path: "/content",
                name: "内容",
                icon: "smile",
                routes: [
                    //采集管理
                    {
                        path: "/content/collectManageMent",
                        name: "采集管理",
                        icon: "smile",
                        routes: [
                            //采集管理
                            {
                                path: "/content/collectManageMent/collectionManageMent",
                                name: "采集管理",
                                icon: "smile", component: "@/pages/Content/CollectManageMent/CollectionManageMent",
                            },
                        ],
                    },
                    //文章管理
                    {
                        path: "/content/articleManageMent",
                        name: "文章管理",
                        icon: "smile",
                        routes: [
                            //文章分类
                            {
                                path: "/content/articleManageMent/articleClassify",
                                name: "文章分类",
                                icon: "smile",
                                component: "@/pages/Content/ArticleManageMent/ArticleClassify",
                            },
                            //文章列表
                            {
                                path: "/content/articleManageMent/articleList",
                                name: "文章列表",
                                icon: "smile",
                                component: "@/pages/Content/ArticleManageMent/ArticleList",
                            },
                            //添加文章
                            {
                                path: "/content/articleManageMent/addArticle",
                                name: "添加文章",
                                icon: "smile",
                                component: "@/pages/Content/ArticleManageMent/AddArticle",
                            },
                            //回收站
                            {
                                path: "/content/articleManageMent/binList",
                                name: "回收站",
                                icon: "smile",
                                component: "@/pages/Content/ArticleManageMent/BinList",
                            },
                            //
                            {
                                path: "/content/articleManageMent/articleadd",
                                name: "增加文章",
                                icon: "smile",
                                component: "@/pages/Content/ArticleManageMent/ArticleAdd",
                            },
                        ],
                    },
                    //单页面管理
                    {
                        path: "/content/pageManageMent",
                        name: "单页面管理",
                        icon: "smile",
                        routes: [
                            //单页面列表
                            {
                                path: "/content/pageManageMent/pageList",
                                name: "单页面列表",
                                icon: "smile",
                                component: "@/pages/Content/PageManageMent/PageList",
                            },
                            // //分类管理
                            {
                                path: "/content/pageManageMent/classifyManageMent",
                                name: "分类管理",
                                icon: "smile",
                                component: "@/pages/Content/PageManageMent/ClassifyManageMent",
                            },
                        ],
                    },
                ],
            },
            {
                path: "/admin",
                name: "admin",
                icon: "crown",
                component: "./Admin",
                authority: ["admin"],
                routes: [
                    {
                        path: "/admin/sub-page",
                        name: "sub-page",
                        icon: "smile",
                        component: "./Welcome",
                        authority: ["admin"],
                    },
                ],
            }, {
                name: "list.table-list",
                icon: "table",
                path: "/list",
                component: "./TableList",
            }]
        let num1 = 0
        let num2 = 1
        let num3 = 1
        list.forEach((item1) => {
            item1.key = num1
            item1.url = item1.name
            inster(item1)
            if (item1.routes && item1.routes.length > 0) {
                item1.routes.forEach((item3) => {
                    item3.key = num1 + '-' + num2
                    item3.url = item1.name + '-' + item3.name
                    inster(item3)
                    if (item3.routes && item3.routes.length > 0) {
                        item3.routes.forEach((item4) => {
                            item4.key = num1 + '-' + num2 + "-" + num3
                            item4.url = item1.name + '-' + item3.name + '-' + item4.name
                            inster(item4)
                            num3++
                        })
                    }
                    num2++
                })
            }
            num2 = 0
            num3 = 0
            num1++
        })
        const data = await app.mysql.query(`select * from routesTable`);
        ctx.body = data;
    }

    async updateRoutes() {
        const { ctx } = this;
        const data = await ctx.service.routes.updateRoutes();
        ctx.body = data;
    }
}

module.exports = RoutesController;